/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dieci.managers.stockmanager;

import dieci.database.product.ProductStockHibernateDAO;
import dieci.system.Product;
import dieci.system.ProductStock;
import java.util.List;

/**
 *
 * @author Blanco
 */
public class StockManager {

    public StockManager() {
        this.productStockDAO = new ProductStockHibernateDAO();
    }
    
    public void saveProductStock(ProductStock productStock)
    {
        //call prod dao to save the productStock in db
        productStockDAO.saveOrUpdate(productStock);        
    }
    
    public ProductStock findByProductId(long id)
    {
        return productStockDAO.findByProductId(id);
    }
    
    public List<ProductStock> list()
    {
        return productStockDAO.list();
    }
  
    public boolean isStockAvailableForProduct(Product product, int amount)
    {
        boolean available = false;
        ProductStock stock = findByProductId(product.getProductId());
        if (stock!=null)
        {
            if(stock.getAvailableAmount() >= amount)
            {
                available = true;
            }
        }
        
        return available;
    }
    
    private ProductStockHibernateDAO productStockDAO;
    
}
